package com.study.concurrent.singleton;

/**
 * Description:
 * User: 27010
 * DateTime: 2018/6/20 23:26
 */
//双重检锁
public class Singleton4 {                         //1
    private static Singleton4 instance;         //2
    private Singleton4() {}                       //3
    public static Singleton4 getInstance() {      //4
        if (instance == null) {                 //5  判断
            synchronized (Singleton4.class) {     //6  加锁
                if (instance == null) {         //7  并发问题所在
                    instance = new Singleton4();//8  new 导致并发问题
                }                                 //9
            }                                     //10
        }                                         //11
        return instance;                        //12
    }
}
